<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.kms.model.*" %>
<%@ page import="java.io.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String sta = (String)request.getAttribute("status");
String url = (String)request.getAttribute("url");

String id = request.getAttribute("id")+"";
MSyspara mssys_db=new MSyspara();
if(request.getAttribute("mssys")!=null){
	mssys_db = (MSyspara)request.getAttribute("mssys");
};
%>
<%!
public String Value (Object v)
{
	String rv = "UnKonw";
	if(v!=null){
		rv = v.toString();
	}
	return rv;
}
%>
<html><head>
<script type="text/javascript">
function statuss(num){
	document.getElementById("status1").value = num;
	var form = document.getElementById("thisform");
    form.submit();
}

if('<%=sta%>'!='stop'){
	setInterval("statuss('start')","3000");
}
</script>

<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
   <title>MBean Inspector</title>
   <link rel="stylesheet" href="<%=basePath %>css/style_master.css" type="text/css">
   <meta http-equiv="cache-control" content="no-cache">
</head>
<body>
<form id="thisform" method="post" action="tbsmonitor">
<input id="status1" name="status1" type="hidden" />
<input id="id" name="id" value="<%=id %>" type="hidden" />
<table width="100%">
   </table><table>
      <tbody><tr>
         <td><img src="<%=basePath %>img/logo02.gif" alt="JBoss" align="left" border="0"></td>
         <td valign="middle"><h1>TBS Monistor View</h1></td>
      </tr><tr>
   </tr></tbody></table>
   <ul>
   <table>
    <li>Introduction :</li>
      <tbody><tr>
         <td><b>TBS server connection monitoring, the main purpose is to check whether tbs jetty web server back alive, if down the screen to provide monitoring and an icon to display the server connection status.</b></td>
      </tr>
   </tbody></table>
</ul>
<!-- server list config start-->
<table width="524" height="49" border="1" cellpadding="1" cellspacing="1" >
	<%
	List<MGroup> listmg = new ArrayList<MGroup>();
	if(request.getAttribute("listmgroup")!=null){
		listmg = (List<MGroup>)request.getAttribute("listmgroup");
	}
	
	MSyspara msapp=new  MSyspara();
	MSyspara msdb = new MSyspara() ;
	List<Map>  listsys = new ArrayList<Map>();
	if(request.getAttribute("listmgroup")!=null){
		for(MGroup mg:listmg){
			Map<String,Object>	mapv = new HashMap<String,Object>();
			mapv.put("mgroup",mg);
			if(mg.getListsyspara()!=null){
				for(int j=0;j<mg.getListsyspara().size();j++){
					MSyspara ms = mg.getListsyspara().get(j);
					if("APP".equals(ms.getDatatype())){
						msapp = ms;
						mapv.put("sysapp",ms);
					}else{
						msdb = ms;
						mapv.put("sysdb",ms);
					}	
				}
			}
			listsys.add(mapv);
		}
	}
	
	MSyspara mssysapp = new MSyspara();
	MSyspara mssysdb = new MSyspara();
	MSyspara mssysapp2 = new MSyspara();
	MSyspara mssysdb2 = new MSyspara();
	MGroup mgroup = new MGroup();
	MGroup mgroup2 = new MGroup();
	for(int i=0;i<listsys.size();){
		Map mapmsyspara = listsys.get(i);
		Map mapmsyspara2 = (i+1)>=listsys.size()?null:listsys.get(i+1);
		if(mapmsyspara!=null ){
			if(mapmsyspara.get("mgroup")!=null){
				mgroup = (MGroup)mapmsyspara.get("mgroup");
			}
			if(mapmsyspara.get("sysapp")!=null ){
				mssysapp = (MSyspara)mapmsyspara.get("sysapp");
			}
			if(mapmsyspara.get("sysdb")!=null ){
				mssysdb = (MSyspara)mapmsyspara.get("sysdb");
			}
		}
		
		if(mapmsyspara2!=null ){
			if(mapmsyspara2.get("mgroup")!=null){
				mgroup2 = (MGroup)mapmsyspara2.get("mgroup");
			}
			if(mapmsyspara2.get("sysapp")!=null ){
				mssysapp2 = (MSyspara)mapmsyspara2.get("sysapp");
			}
			if(mapmsyspara2.get("sysdb")!=null ){
				mssysdb2 = (MSyspara)mapmsyspara2.get("sysdb");
			}
		}
		
		%>
	  <tr>
	    <td width="51" rowspan="2"><%=(mgroup).getName() %></td>
	    <td width="72" bgcolor="#CCCCCC">
	    	<a href="<%=basePath %>tbsmonitor?id=<%=(mssysapp).getId() %> " >
	    		<%=(mssysapp).getDatatype() %>
	    	</a>
	    </td>
	    <td width="121">
	    	<a href="<%=basePath %>tbsmonitor?id=<%=(mssysapp).getId() %> " >
	    		<%=(mssysapp).getOsip() %>
	    	</a>
	    </td>
	<%
	    if(mapmsyspara2!=null){
	    	%>
			    <td width="51" rowspan="2">
					    <%=(mgroup2).getName() %>
				</td>
			    <td width="60" bgcolor="#CCCCCC">
				    <a href="<%=basePath %>tbsmonitor?id=<%=(mssysapp2).getId() %> " >
				    	<%=(mssysapp2).getDatatype() %>
				    </a>
			    </td>
			    <td width="136">
			    	<a href="<%=basePath %>tbsmonitor?id=<%=(mssysapp2).getId() %> " >
			    		<%=(mssysapp2).getOsip() %>
			    	</a>
			    </td>
	    	<%
	    }
	%>
	
	  </tr>
	  <tr>
	    <td bgcolor="#CCCCCC">
	    		<%=(mssysdb).getDatatype() %>
	    </td>
	    <td>
	    		<%=(mssysdb).getOsip() %>
	    </td>
	<%
	    if(mapmsyspara2!=null){
	    	%>
				<td bgcolor="#CCCCCC">
		    		<%=(mssysdb2).getDatatype() %>
			    </td>
			    <td>
			    		<%=(mssysdb2).getOsip() %>
			    </td>
	    	<%
	    }
	%>
	  </tr>
		<%
		i=i+2;}
	%>
</table> 
<!-- server list config end-->
<table cellpadding="5">
   <tbody><tr>
     <td><a href="#">Refresh MBean View</a></td>
   </tr>
</tbody></table>

<hr>
<h3>TBSMonitor description:</h3>
TBS Monitor Server URL : <%=url %><br/><br/>

<input value="TBS Monitor Start" type="button" onclick="javascript:statuss('start');"/>

<input value="TBS Monitor Stop" type="button" onclick="javascript:statuss('stop');" />
<br><br>



<% 
if("alive".equals(sta)){
	%>
	
	<div align="center">
	<div align="center">status:<b><font size="3"> Normal</font></b></div><br/>
	<img src="<%=basePath %>img/run.gif" alt="Run" style="width: 100px;height: 100px"/>
	</div>
	
	<%
}else if("error".equals(sta)){
	%><div align="center">status:<b><font size="3"> Error</font></b></div><br/>
	<div align="center">
	<img src="<%=basePath %>img/alarm.gif" alt="Alarm" style="width: 400px;height: 100px"/>
	</div>
	<%
}
%>

</form>
</body></html>